public class SendPERequest {
   
    @Future(callout=true)
    public static void SendOrderToDistributor(Id PeRequestId)
    {

        PESampleRequest__c PeRequest =[Select  p.SubRegion__c, p.SendShipment__c, p.ThisEvaluationNum__c,p.HCP__r.name,
            p.SalesCity__c, p.OwnerId, p.OutpatientServiceNumber__c, p.OrderDate__c, p.Name, p.HCP__r.mobile__c,p.ApproveDatebyRGM__c,
            p.NICULowBirthweightNumber__c, p.MothersMilkFeedingRate__c, p.MonthlyNewBornNum__c,p.RSM__c, p.ApproveDatebyRSM__c,
            p.MonthlyNewBornHospitalizedSeveral__c, p.LineManager__c, p.LineManagerId__c,p.ApproveDate__c,
            p.LastApprover__c,  p.KG__c,  p.InHospitalAverageDays__c, p.HospitalCode__c, 
            p.Id, p.Hospital__c,p.Hospital__r.name, p.Owner.Alias,
            p.HCP__c, p.HCPCode__c, p.FeedNumberByDay__c, p.FeedDays__c, p.Department__c, p.DateShipped__c,
            p.ChildrenDiarrheaNumber__c, p.CenterPKUNumber__c,
            p.ApprovalStatus__c From PESampleRequest__c p where Id=:PeRequestId];
         
        List<AggregateResult> pItem = [Select sum(Unit__c) unit,Product__c PN From PESampleRequestItem__c Where PESampleRequest__c =: PeRequestId Group By Product__c];

        if(PeRequest != NULL)
        {
        /*
            Distributor__c dis=[Select Name, Fax__c, Email__c From Distributor__c where SendPESample__c =: true and SalesCity__c =: PeRequest.SalesCity__c];
            SendFax(PeRequest, pItem, dis);
        */
            Distributor__c dis=[Select Name, FaxMedical__c,Fax__c, Email__c From Distributor__c where id =: 'a0UO00000004o4C'];
            String msg = SendFax(PeRequest, pItem, dis);
            
        }

    }

    
    public static String SendFax(PESampleRequest__c order,List<AggregateResult> oItem,Distributor__c dis)
    {
        String body;
        String fax=dis.FaxMedical__c;
        if(fax != NULL)
        {
            List<Attachment> fileList=[select Body from Attachment where ParentId=:order.Id order by CreatedDate asc limit 1];
            String html = getBodyString(order,oItem,dis);
            
            String fileName = 'Fax.html';
            ExternalWebServiceConfiguration__c ex=ExternalWebServiceConfiguration__c.getValues('HiFax');
           
            String fileEncoding =EncodingUtil.base64Encode(Blob.valueOf(html));
            
            String xml = createXML(String.valueOf(ex.UserName_del__c),String.valueOf(ex.Password__c),String.valueOf(ex.AccessKey__c),fileName,fileEncoding,dis,fileList,'编码: ',order.id);
            String xmlPic;
            if(fileList!=NULL && fileList.size()>0)
            {
                xmlPic = createPicture(String.valueOf(ex.UserName_del__c),String.valueOf(ex.Password__c),String.valueOf(ex.AccessKey__c),fileName,fileEncoding,dis,fileList,'编码:'+order.id ,'医院/医疗机构负责人签名：');
            }            

            try
            {
                HiFaxCallOut.FaxServiceSoap c = new HiFaxCallOut.FaxServiceSoap();
                body = c.SendFax(xml);
                body = c.SendFax(xmlPic);
                body='用传真发送订单到经销商成功';
            }
            catch(CalloutException e)
            {
                body='用传真发送订单到经销商失败'+e.getMessage();
            }
        }
        return body;
    }
    
     private static String createXML(String userName,String pwd,String key,String fileName,String fileEncoding,Distributor__c dis,List<Attachment> fileList,String page,String RequestId)
     {
        String xml = '<?xml version="1.0" encoding="UTF-8"?>';
        xml += '<SendFaxReq>';
        xml += '<Head>';
        xml += '<UserInfo>';
        xml += '<UserName>'+userName+'</UserName>';
        xml += '<Password>'+pwd+'</Password>';
        xml += '<Accresskey>'+key+'</Accresskey>';
        xml += '</UserInfo>';
        xml += '</Head>';
        xml += '<Body>';
        xml += '<SendFileList>';

        xml += '<SendFile>';
        xml += '<FileName>' + fileName + '</FileName>';
        xml += '<FileEncoding>' + fileEncoding + '</FileEncoding>';
        xml += '</SendFile>';

        xml += '</SendFileList>';
        xml += '<RecipientList>';
        xml += '<Recipient>';
        xml += '<ClientName>'+RequestId+'</ClientName>';
        xml += '<Company>'+ page +'</Company>';
        xml += '<FaxNumber>'+dis.FaxMedical__c+'</FaxNumber>';
        xml += '</Recipient>';
        xml += '</RecipientList>';
        xml += '</Body>';
        xml += '</SendFaxReq>';
        return xml;
    }

     private static String createPicture(String userName,String pwd,String key,String fileName,String fileEncoding,Distributor__c dis,List<Attachment> fileList,String page,String RequestId)
     {
        String xml = '<?xml version="1.0" encoding="UTF-8"?>';
        xml += '<SendFaxReq>';
        xml += '<Head>';
        xml += '<UserInfo>';
        xml += '<UserName>'+userName+'</UserName>';
        xml += '<Password>'+pwd+'</Password>';
        xml += '<Accresskey>'+key+'</Accresskey>';
        xml += '</UserInfo>';
        xml += '</Head>';
        xml += '<Body>';
        xml += '<SendFileList>';

        xml += '<SendFile>';
        xml += '<FileName>电子签名.bmp</FileName>';
        xml += '<FileEncoding>' + EncodingUtil.base64Encode(fileList.get(0).Body)+ '</FileEncoding>';
        xml += '</SendFile>';

        xml += '</SendFileList>';
        xml += '<RecipientList>';
        xml += '<Recipient>';
        xml += '<ClientName>'+RequestId+'</ClientName>';
        xml += '<Company>'+ page +'</Company>';
        xml += '<FaxNumber>'+dis.FaxMedical__c+'</FaxNumber>';
        xml += '</Recipient>';
        xml += '</RecipientList>';
        xml += '</Body>';
        xml += '</SendFaxReq>';
        return xml;
    }

    
    
    public static String getBodyString(PESampleRequest__c PeRequest,List<AggregateResult> pItem,Distributor__c dis)
    {
        Boolean colum1 = false;
        Boolean colum2 = false;
        Boolean colum3 = false;

        Product2 product1 = [Select p.Id From Product2 p where p.Name =: '安婴儿A+无乳糖400克罐装（样品）' and p.Product_Type__c =: 'PE Sample'];
        Product2 product2 = [Select p.Id From Product2 p where p.Name =: '安婴儿A+200克盒装（样品）' and p.Product_Type__c =: 'PE Sample'];
        Product2 product3 = [Select p.Id From Product2 p where p.Name =: '安婴儿A+400克罐装（样品）' and p.Product_Type__c =: 'PE Sample'];
        Product2 product4 = [Select p.Id From Product2 p where p.Name =: '安婴儿A+早产儿配方奶粉400克罐装（样品）' and p.Product_Type__c =: 'PE Sample'];
        Product2 product5 = [Select p.Id From Product2 p where p.Name =: '安婴儿A+早产儿配方奶59毫升×6瓶装（样品）'and p.Product_Type__c =: 'PE Sample'];
        Product2 product6 = [Select p.Id From Product2 p where p.Name =: '美赞臣无苯丙氨酸配方粉（1阶段）454克罐装' and p.Product_Type__c =: 'PE Sample'];
        Product2 product7 = [Select p.Id From Product2 p where p.Name =: '安婴乐450克罐装（样品）' and p.Product_Type__c =: 'PE Sample'];
        
        if((PeRequest.Department__c == '产科PE')||(PeRequest.Department__c == '新生儿科PE')||(PeRequest.Department__c == '产科RO')||(PeRequest.Department__c == '新生儿科RO'))
            colum1 = true;
        if((PeRequest.Department__c == '产科门诊1')||(PeRequest.Department__c == '产科门诊2')||(PeRequest.Department__c == '儿保门诊2')||(PeRequest.Department__c == '儿保门诊2'))
            colum2 = true;    
        if(PeRequest.Department__c == '特殊配方')
            colum3 = true;    
    
        String mailBody='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
        mailBody+='<html xmlns="http://www.w3.org/1999/xhtml">';  
        mailBody+='<head>'; 
        mailBody+='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
        mailBody+='<br />';
        mailBody+='<title>专业评估样品需求表</title>';
        mailBody+='<style type="text/css">';
        mailBody+=' .tbl td';
        mailBody+=' { border: 1px #000000 solid; font-size: 12px;}';
  
        mailBody+='</style>';
        mailBody+='</head>';
        mailBody+='<body>';
        mailBody+='<div style="width:210mm; height:230mm;">';
        mailBody+='  <div id="al" style=" float:left;width:680px;height:auto; border-right: solid #000000 1px ">';
        mailBody+='  <div id="hdr" style="width:650px;height:auto">';
        mailBody+='     <h3 style="text-align:center; text-weight:bold; text-size:16px;">专业评估样品需求表</h3>';
        mailBody+='        <table width="650">';
        mailBody+='         <tr>';
        mailBody+='             <td width="150">医院/医疗保健机构:</td>';
        mailBody+='              <td style="font-size:14px;text-decoration: underline">'+ PeRequest.Hospital__r.name +'</td>';
        mailBody+='                <td width="110" style="float:right">SFA系统编码:</td>';
        mailBody+='                <td width="100" style="float:right;font-size:14px;text-decoration: underline">'+ PeRequest.HospitalCode__c +'</td>'; 
        mailBody+='          </tr>';
        mailBody+='    </table>';
        mailBody+='<p style="font-size:14px">本人明白遵照世界卫生组织国际守则第7.4条，美赞臣营养品（中国）有限公司的婴儿营养配方样品'+ '<br>' +'提供给保健工作者仅仅是供他们“进行专业评估或作为机构内研究”的用途。</p>';
        mailBody+='</div>';
        mailBody+='<div style="width:350px; height:auto">';
        mailBody+='<table class="tbl">';
        mailBody+='<tr>';
        if(PeRequest.Department__c == '产科PE')
            mailBody+='<td colspan="2" style="text-align:right;border-right:none; border-bottom:none" >产科：PE<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td colspan="2" style="text-align:right;border-right:none; border-bottom:none" >产科：PE<input type="checkbox" name="checkbox1" value="checkbox"/></td>';
        if(PeRequest.Department__c == '新生儿科PE')
            mailBody+='<td width="150" style="text-align:center; border-left:none; border-bottom:none">&nbsp;&nbsp;新生儿科：PE<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td width="120" style="text-align:center; border-left:none; border-bottom:none">&nbsp;&nbsp;新生儿科：PE<input type="checkbox" name="checkbox1" value="checkbox"/></td>';
        if(PeRequest.Department__c == '产科门诊1')
            mailBody+='<td width="88" style="border-bottom:none; border-right:none">产科门诊1<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td width="88" style="border-bottom:none; border-right:none">产科门诊1<input type="checkbox" name="checkbox1" value="checkbox"/></td>';
        if(PeRequest.Department__c == '儿保门诊1')
            mailBody+='<td width="88" style="border-bottom:none; border-left:none">儿保门诊1<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td width="88" style="border-bottom:none; border-left:none">儿保门诊1<input type="checkbox" name="checkbox1" value="checkbox"/></td>';

        mailBody+='<td width="160" rowspan="2" colspan="2" style="text-align:center">特殊配方</td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        if(PeRequest.Department__c == '产科RO')
            mailBody+='<td colspan="2" style="text-align:right; border-right:none; border-top:none">RO<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td colspan="2" style="text-align:right; border-right:none; border-top:none">RO<input type="checkbox" name="checkbox1" value="checkbox"/></td>';
        if(PeRequest.Department__c == '新生儿科RO')
            mailBody+='<td style="padding-left:80px; border-left:none;border-top:none">RO<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>'; 
        else
            mailBody+='<td style=" padding-left:80px; border-left:none; border-top:none">RO<input type="checkbox" name="checkbox1" value="checkbox"/></td>'; 
        if(PeRequest.Department__c == '产科门诊2')
            mailBody+='<td style="border-top:none; border-right:none">产科门诊2<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td style="border-top:none; border-right:none">产科门诊2<input type="checkbox" name="checkbox1" value="checkbox"/></td>';
        if(PeRequest.Department__c == '儿保门诊2')
            mailBody+='<td style="border-top:none; border-left:none">儿保门诊2<input type="checkbox" name="checkbox1" value="checkbox" checked="true"/></td>';
        else
            mailBody+='<td style="border-top:none; border-left:none">儿保门诊2<input type="checkbox" name="checkbox1" value="checkbox"/></td>';        
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td width="96">医院月出生数/住院数</td>';
        if(colum1)
            mailBody+='<td colspan="2">' + PeRequest.MonthlyNewBornHospitalizedSeveral__c + '</td>';
        else
            mailBody+='<td colspan="2"></td>';
           
        mailBody+='<td>医院月出生数</td>';
        if(colum2) 
            mailBody+='<td>' +PeRequest.MonthlyNewBornNum__c + '</td>';
        else
            mailBody+='<td></td>';
        mailBody+='<td width="96">NICU低体重儿人数</td>';
        if(colum3)
            mailBody+='<td width="96" colspan="2">' + PeRequest.NICULowBirthweightNumber__c + '</td>';
        else
            mailBody+='<td width="96" colspan="2"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td>母乳喂养率%</td>';
        if(colum1)
            mailBody+='<td colspan="2">' + integer.valueof(PeRequest.MothersMilkFeedingRate__c) + '%</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='<td>母乳喂养率%</td>';
        if(colum2)
            mailBody+='<td>' + integer.valueof(PeRequest.MothersMilkFeedingRate__c) + '%</td>';
        else
            mailBody+='<td ></td>';
        mailBody+='<td width="96">新筛中心PKU患儿数</td>';
        if(colum3)
            mailBody+='<td width="96" colspan="2">' +PeRequest.CenterPKUNumber__c + '</td>';
        else
            mailBody+='<td width="96" colspan="2"></td>';
        mailBody+='</tr>'; 
        mailBody+='<tr>';
        mailBody+='<td>本次拟评估人数</td>';
        if(colum1)
            mailBody+='<td colspan="2">' +PeRequest.ThisEvaluationNum__c + '</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='<td>门诊人数</td>';
        if(colum2)
            mailBody+='<td>' + PeRequest.OutpatientServiceNumber__c  + '</td>';
        else
            mailBody+='<td></td>';
        mailBody+='<td width="96">腹泻婴儿人数</td>';
        if(colum3)
            mailBody+='<td colspan="2">' +PeRequest.ChildrenDiarrheaNumber__c + '</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td>住院平均日数</td>';
        if(colum1)
            mailBody+='<td colspan="2">'+PeRequest.InHospitalAverageDays__c + '</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='<td>本次拟评估人数</td>';
        if(colum2)
            mailBody+='<td>'+PeRequest.ThisEvaluationNum__c + '</td>';
        else
            mailBody+='<td></td>';
        mailBody+='<td width="96">本次拟评估人数</td>';
        if(colum3)
            mailBody+='<td>'+PeRequest.ThisEvaluationNum__c + '</td>';
        else
            mailBody+='<td></td>';    
        mailBody+='</tr>';  
        mailBody+='<tr>';
        mailBody+='<td>每日平均喂哺次数</td>'; 
        if(colum1)
            mailBody+='<td colspan="2">'+PeRequest.FeedNumberByDay__c +'</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='<td>拟喂哺日数</td>';
        if(colum2)
            mailBody+='<td>'+PeRequest.FeedDays__c +'</td>';
        else
            mailBody+='<td></td>';
        mailBody+='<td width="96">拟喂哺日数</td>';
        if(colum3)
            mailBody+='<td colspan="2">'+PeRequest.FeedDays__c + '</td>';
        else
            mailBody+='<td colspan="2"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td colspan="3">&nbsp;</td>';
        mailBody+='<td>每日平均喂哺次数</td>';
        if(colum2)
            mailBody+='<td>'+PeRequest.FeedNumberByDay__c +'</td>';
        else
            mailBody+='<td></td>';
        mailBody+='<td width="96">每日平均喂哺次数</td>';
        if(colum3)
            mailBody+='<td>'+ PeRequest.FeedNumberByDay__c +'</td>';
        else
            mailBody+='<td></td>';
        mailBody+='</tr>';
        mailBody+='</table>';
        mailBody+='</div>';
        mailBody+='  <div style="width:620px;">'; 
        mailBody+='     <p style="font-size:14px">本人申请以下奶粉供上述的用途（罐/盒/袋/瓶）</p>';
        mailBody+='<table class="tbl" width="620" >';
        mailBody+='<tr>'; 
        mailBody+='<td style="text-align:center" width="88">安婴儿A+'+'<br>'+'无乳糖配方</td>';
        mailBody+='<td style="text-align:center" colspan="2" width="50">安婴儿A+</td>';
        mailBody+='<td style="text-align:center" colspan="2" width="78">安婴儿A+ '+'<br>'+'早产儿配方</td>';
        mailBody+='<td style="text-align:center" width="118">无苯丙氨酸配方</td>';
        mailBody+='<td style="text-align:center" width="58">安婴乐</td>';
        mailBody+='<td style="text-align:center" width="118"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td style="text-align:center" width="58">400g</td>';
        mailBody+='<td style="text-align:center" width="48">200g</td>';
        mailBody+='<td style="text-align:center" width="48">400g</td>';
        mailBody+='<td style="text-align:center" width="48">400g</td>';
        mailBody+='<td style="text-align:center" width="48">59ml</td>';
        mailBody+='<td style="text-align:center" >454g</td>';
        mailBody+='<td style="text-align:center" width="58">450g</td>';
        mailBody+='<td style="text-align:center" width="118"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        integer num1;
        integer num2;
        integer num3;
        integer num4;
        integer num5;
        integer num6;
        integer num7;
        for(AggregateResult ag : pItem)
        {
            if(String.valueof(ag.get('PN')) == product1.id)
                num1 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product2.id)
                num2 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product3.id)
                num3 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product4.id)
                num4 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product5.id)
                num5 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product6.id)
                num6 = integer.valueof((Double )ag.get('unit'));
            if(String.valueof(ag.get('PN')) == product7.id)
                num7 = integer.valueof((Double )ag.get('unit'));                                                                                                              
        }
        if(num1 > 0)
            mailBody+='<td style="text-align:center">' + num1 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num2 > 0)
            mailBody+='<td style="text-align:center">' + num2 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num3 > 0)
            mailBody+='<td style="text-align:center">' + num3 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num4 > 0)
            mailBody+='<td style="text-align:center">' + num4 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num5 > 0)
            mailBody+='<td style="text-align:center">' + num5 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num6 > 0)
            mailBody+='<td style="text-align:center">' + num6 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';
        if(num7 > 0)
            mailBody+='<td style="text-align:center">' + num7 + '</td>';
        else
            mailBody+='<td style="text-align:center">' + 0 + '</td>';                                                                          

        mailBody+='<td ></td>';
        mailBody+='</tr></table></div>';

        mailBody+='<div style="" class=".comment-body{height:100%}" >';
        mailBody+='<table style="font-size:14px" width="620">';
        mailBody+='<tr>';
        
        mailBody+='<td>医院/医疗机构负责人:'+ PeRequest.HCP__r.name +'</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;申请日期:</td>';
        mailBody+='<td>'+ PeRequest.OrderDate__c.year() +'年</td>'; 
        mailBody+='<td>'+ PeRequest.OrderDate__c.month() +'月</td>';
        mailBody+='<td style="text-align:right">'+ PeRequest.OrderDate__c.day() +'日</td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td colspan="5">联系电话:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+PeRequest.HCP__r.mobile__c+'</td>';
        mailBody+='</tr>';

        mailBody+='<tr>';
        if(PeRequest.Owner.Alias != null)
            mailBody+='<td>公司审批人1:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+PeRequest.Owner.Alias+'</td>';
        else
            mailBody+='<td>公司审批人1:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+ ' '+'</td>';
           
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批日期:</td>';
        mailBody+='<td>' + PeRequest.OrderDate__c.year() + '年</td>';
        mailBody+='<td>' + PeRequest.OrderDate__c.month() + '月</td>';
        mailBody+='<td style="text-align:right">' + PeRequest.OrderDate__c.day() + '日</td>';
        mailBody+='</tr>';    
        
        mailBody+='<tr>';
        if(PeRequest.LineManager__c != null)
            mailBody+='<td>公司审批人2:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+PeRequest.LineManager__c+'</td>';
        else
            mailBody+='<td>公司审批人2:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+ ' '+'</td>';
           
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批日期:</td>';
        mailBody+='<td>' + PeRequest.ApproveDate__c.year() + '年</td>';
        mailBody+='<td>' + PeRequest.ApproveDate__c.month() + '月</td>';
        mailBody+='<td style="text-align:right">' + PeRequest.ApproveDate__c.day() + '日</td>';
        mailBody+='</tr>';        
        
        mailBody+='<tr>';
        if(PeRequest.RSM__c != null)
            mailBody+='<td>公司审批人3:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+PeRequest.RSM__c+'</td>';
        else
            mailBody+='<td>公司审批人3:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+' '+'</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批日期:</td>';
        if(PeRequest.ApproveDatebyRSM__c != null)
            mailBody+='<td>' + PeRequest.ApproveDatebyRSM__c.year() + '年</td>';
        else
            mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;年</td>';
        if(PeRequest.ApproveDatebyRSM__c != null)
            mailBody+='<td>' + PeRequest.ApproveDatebyRSM__c.month() + '月</td>';
        else
            mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;月</td>';
        if(PeRequest.ApproveDatebyRSM__c != null)    
            mailBody+='<td style="text-align:right">' + PeRequest.ApproveDatebyRSM__c.day() + '日</td>';
        else
            mailBody+='<td style="text-align:right">&nbsp;&nbsp;&nbsp;&nbsp;日</td>';
        mailBody+='</tr>';
        
        mailBody+='<tr>';
        if(PeRequest.LastApprover__c != null)
            mailBody+='<td>公司审批人4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+PeRequest.LastApprover__c+'</td>';
        else    
            mailBody+='<td>公司审批人4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+' '+'</td>';        
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批日期:</td>';
        if(PeRequest.ApproveDatebyRGM__c != null)
            mailBody+='<td>' + PeRequest.ApproveDatebyRGM__c.year() + '年</td>';
        else
            mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;年</td>'; 
        if(PeRequest.ApproveDatebyRGM__c != null)   
            mailBody+='<td>' + PeRequest.ApproveDatebyRGM__c.month() + '月</td>';
        else
            mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;月</td>';
        if(PeRequest.ApproveDatebyRGM__c != null) 
            mailBody+='<td style="text-align:right">' + PeRequest.ApproveDatebyRGM__c.day() + '日</td>';
        else
            mailBody+='<td style="text-align:right">&nbsp;&nbsp;&nbsp;&nbsp;日</td>';
        mailBody+='</tr>';
                                      

        mailBody+='<tr>'; 
        mailBody+='<td>M&P负责人:</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出仓日期:</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;年</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月</td>';
        mailBody+='<td style="text-align:right">&nbsp;&nbsp;&nbsp;日</td>';
        mailBody+='</tr>';
        mailBody+='</table>';
        mailBody+='    <hr size="1" style="border:1px #000000 dotted"/>';
        mailBody+='    <h3 style="margin-left:250px">收条</h3>';
        mailBody+='    <p style="font-size:14px">兹收到美赞臣营养品（中国）有限公司送来(罐/盒/袋/瓶)</p>';
        mailBody+='<table class="tbl" width="620">';
        mailBody+='<tr>';
        mailBody+='<td width="88" style="text-align:center">安婴儿A+'+'<br>'+'无乳糖配方</td>';
        mailBody+='<td colspan="2" style="text-align:center" width="50">安婴儿A+</td>';
        mailBody+='<td colspan="2" style="text-align:center" width="78">安婴儿A+ '+'<br>'+'早产儿配方</td>';
        mailBody+='<td width="118" style="text-align:center">无苯丙氨酸配方</td>';
        mailBody+='<td width="58" style="text-align:center">安婴乐</td>';
        mailBody+='<td width="118" style="text-align:center"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td width="58" style="text-align:center">400g</td>';
        mailBody+='<td width="48" style="text-align:center">200g</td>';
        mailBody+='<td width="48" style="text-align:center">400g</td>';
        mailBody+='<td width="48" style="text-align:center">400g</td>';
        mailBody+='<td width="48" style="text-align:center">59ml</td>';
        mailBody+='<td style="text-align:center">454g</td>';
        mailBody+='<td width="58" style="text-align:center">450g</td>';
        mailBody+='<td width="118" style="text-align:center"></td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td>&nbsp;</td>';
        mailBody+='<td >&nbsp;</td>';
        mailBody+='</tr>';
        mailBody+='</table>';
        mailBody+='<table style=" font-size:14px" width="620">';          
        mailBody+='<tr>';
        mailBody+='<td  width="200">送件人:</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;收件日期:</td>';
        mailBody+='<td width="50">年</td>';
        mailBody+='<td>&nbsp;&nbsp;&nbsp;月</td>';
        mailBody+='<td style="text-align:right">&nbsp;&nbsp;&nbsp;日</td>';
        mailBody+='</tr>';
        mailBody+='<tr>';
        mailBody+='<td width="200">收件人:</td>';
        mailBody+='<td colspan="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联系电话:</td>';
        mailBody+='</tr>';
        mailBody+='</table>'; 
        mailBody+='</div>';
        mailBody+='</div>';

        mailBody+='</div>';                                   
        mailBody+='</body>';
        mailBody+='</html>';
                                     
        return mailBody;
    }
    
    
    static testmethod void test()
    {
        

    }
}